package domain;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;


import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.image.BufferedImage;

import javax.imageio.ImageIO;
import javax.swing.*;

import visual.BossVisual;

/**
 * Central class for controlling the process of reading and processing the csv into 
 * Large4DArray and writing it to a random access file (raf); Be aware that no checks
 * are done on the availability and writeability of previously written files with identical file 
 * names. The most safe way is to remove those files from the directory before rewriting them.
 * If not, some erratic behavior of the files may show, e.g. the raf will be sometimes
 * overwritten, but not always.
 * Also, when a file is in use by any application, it will not be overwritten and no message 
 * will be shown. So, when do not you remove the existing files, than check on the time stamps whether all have 
 * been rewritten.  
 * @author kooijmanj1
 *
 */
public class Boss extends JFrame{
	private static String name = "voxels_37w";
	private static final String VOXELFILE = "C:/Data/GeoTOP/37wInput/voxels_37w.csv";
	private static final String METADATA = "C:/Data/GeoTOP/37wOutputEnriched/" + "meta_" + "37w.csv";
	private static final String INFILE3="C:/Data/GeoTOP/37wInput/Lithoklasse.voleg";
	private static final String INFILE4="C:/Data/GeoTOP/37wInput/Lithostratigrafie.voleg";
	private static final String OUTFILE3="C:/Data/GeoTOP/37wOutput/Lithoklasse.csv";
	private static final String OUTFILE4="C:/Data/GeoTOP/37wOutput/Lithostratigrafie.csv";
	private static final String LKPFILE = "C:/Data/GeoTOP/37wOutput/Lithoklasse.csv"; 
	private static final String LSPFILE = "C:/Data/GeoTOP/37wOutput/Lithostratigrafie.csv";
	private static final String PFILE = "C:/Data/GeoTOP/37wOutput/HeatCapacity.csv";
	private static final String TITLE = "37W zonder maaiveld, z=0, HeatCapacity";
	
	public Boss(){
		super();
		initialize();
	}
	
	private void initialize(){
		this.setTitle(TITLE);
		Container panel = this.getContentPane();
		panel.setPreferredSize(new Dimension(520,400));
		panel.setBackground(Color.LIGHT_GRAY);
		Vierkant vierkant = new Vierkant(new File(METADATA) , "C:/Data/GeoTOP/37wOutputEnriched/"+ name + ".raf", new File(PFILE));
		panel.add(vierkant);
		pack();
	}
	
	/**
	 * Starts up the reading of the various files extracted from the svp archive.'
	 * Starts up the writing of the converted files for later use.'
	 * The reading plus writing operations delegated to instance of class Geotop4DArray 
	 * is timed. Normally this will take some 100 seconds for 1 map sheet of GeoTOP.
	 * @param args
	 */
	public static void main(String[] args) throws IOException, FileNotFoundException{
		Boss visual = new Boss();
		visual.setVisible(true);
		visual.setDefaultCloseOperation(EXIT_ON_CLOSE);
		
		BufferedImage image = new BufferedImage(visual.getWidth(),visual.getHeight(),
				BufferedImage.TYPE_INT_RGB);
		Graphics2D graphics2D = image.createGraphics();
		visual.paint(graphics2D);
		ImageIO.write(image,"png", new File("C:/Data/GeoTOP/37wImages/" + TITLE + ".png"));
	}
}
